package com.itheima.job;

import com.itheima.constant.RedisConstant;
import com.itheima.untils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Set;

public class DeleteImgJob {
    @Autowired
    private JedisPool jedisPool;
    public void deleteImg(){
        //查询两个集合中的差值
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        System.out.println(sdiff);
        //判断并遍历
        if (sdiff!=null){
            for (String fileName : sdiff) {
                //删除七牛云中的垃圾图片
                QiniuUtils.deleteFileFromQiniu(fileName);
                //删除缓存中的垃圾图片
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,fileName);
                System.out.println("已经删除垃圾:"+fileName);
            }
        }
        System.out.println("您没有垃圾"+new Date());
    }
}
